package com.code2roc.jarmanage.firewall;

import com.code2roc.jarmanage.util.CMDUtil;

import java.text.MessageFormat;

public class WindowsFireWallService implements FireWallService {

    @Override
    public boolean addRule(String name, String protocol, String port, String action) {
        String command = MessageFormat.format("netsh advfirewall firewall add rule name=\"{0}\" dir=in protocol={1} localport={2} action={3} ", name, protocol, port, action);
        String result = CMDUtil.executeWindowCommand(command);
        if (result.contains("确定")) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean deleteRule(String name, String protocol, String port, String action) {
        String command = MessageFormat.format("netsh advfirewall firewall delete rule name=\"{0}\" ", name);
        String result = CMDUtil.executeWindowCommand(command);
        if (result.contains("确定")) {
            return true;
        } else {
            return false;
        }
    }
}
